!function (e, $, mui) {
    "use strict";
	var config = {
	};
	// 定义页面
	var p = function(config) {
		var t = this;
		t.config = config;
		t.userInfo = null;
		t.page = {
			page: 0,
			perpage: 0,
			more: true
		};
		t.element = {
			listContainer: $('#list-container .list'),
			emptyContainer: $('#list-container .empty-list'),
		};
		// 初始化
		t.init();
		
		// 事件监听
		t.listen();
	};
	
	var pt = p.prototype;
	
	// 页面初始化
	pt.init = function () {
		var t = this;
		t.userInit();
		// 列表加载
//		t.listInit();
	};
	
	// 事件初始化
	pt.listen = function() {
		var t = this;
		// 刷新列表
		t.element.emptyContainer.on('tap', function () {
			t.listInit();
		});
		
		// 二维码弹出
		t.element.listContainer.on('tap', '.qrcode', function () {
			var url = $(this).data('url');
			console.log(url);
			openBigImage(url, true);
		});
	};
	
	// 列表初始化
	pt.listInit = function() {
		var t = this;
		t.element.listContainer.html('');
		t.page = {
			page: 0,
			perpage: 5,
			more: true
		};
		
		// 列表加载
		t.listLoad();
	};
	
	// 列表加载
	pt.listLoad = function() {
		var t = this;
		t.page.page++;
		
		if(t.page.more === false) {
			mui('#list-container').pullRefresh().endPulldown();
			mui('#list-container').pullRefresh().endPullup();
			return;
		}
		
		baseApi.post({
			op: 'preEntryList',
			user_id: userInfo.userid,
			page: t.page.page,
			prepage: t.page.perpage
		}, function (result) {
			result = result.result;
			var i = 0;
			result.data.forEach(function (item) {
				i++;
				var html = '<li>';
				html += '<h4>提单号：'+item.bl_no+'</h4>';
				html += '<cite>船公司</cite><em>'+item.ship_company+'</em>';
				html += '<cite>船名/航次</cite><em>'+item.vessel+' / '+item.voyage_no+'</em>';
				html += '<cite>箱型/箱号</cite><em>'+item.container_type+'/'+item.container_no+'</em>';
				if(item.qrcode) {
					html += '<em class="qrcode fa fa-qrcode" data-url="'+item.qrcode+'"></em>';
				}
				html += '</li>';
				t.element.listContainer.append(html);
			});
			
			// 判断列表是否为空
			if(t.page.page == 1) {
				if(i > 0) {
					t.element.listContainer.show();
					t.element.emptyContainer.hide();
				} else {
					t.element.listContainer.hide();
					t.element.emptyContainer.show();
				}
			}
			
			if(i < t.page.perpage) {
				t.page.more = false;
				mui('#list-container').pullRefresh().disablePullupToRefresh();
			} else {
				mui('#list-container').pullRefresh().enablePullupToRefresh();
			}
			mui('#list-container').pullRefresh().endPulldown();
			mui('#list-container').pullRefresh().endPullup();
		});
	};
	
	// 用户信息初始化
	pt.userInit = function() {
		var t = this;
		t.userInfo = getLocalUserInfo();
	};
	
	e.page = new p(config);
	mui.init({
		pullRefresh: {
			container: '#list-container',
			down: {
				style: 'circle',
				callback: function () {
					e.page.listInit();
				}	// 下拉刷新
			},
			up: {
				auto: false,
				contentrefresh: '正在加载...',
				callback: function () {	// 上拉加载
					e.page.listLoad();
				}
			}
		}
	});
	// 页面初始化
	mui.plusReady(function () {
		// 登录判断
		checkUserLogin();
		e.page.listInit();
		
		plus.navigator.setStatusBarBackground('#3E7FC3');
	});

}(window, $, mui);